home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / graphic / cheetah.zip / UPUTZ4P.C < prev    next >
C/C++ Source or Header  |  1992-09-09  |  10KB  |  254 lines

  1. /* uputz4p.c  -  Decoding image in Z4Plane format to VRAM, UNCHAINED mode.
  2.  *
  3.  * Description:
  4.  *   Uses the coding method, described in mputz4p.c
  5.  * See Also:
  6.  *      mputz4p.c
  7.  * Functions:
  8.  *      UputZ4Planes(), UZ4PRequest().
  9.  * Portability: BORLANDC
  10.  * Date: 05/20/92                               (c) erdy 1992
  11.  * $Header: $
  12.  */
  13. #pragma inline
  14. #include "far.h"
  15. #include "vgaprefx.h"
  16. #include "vgadrv.h"
  17. #include "screen.h"
  18.  
  19. #ifndef VGA_UNCHAINED
  20. #    undef BPERROW
  21. #    define BPERROW BPERROW_UNCHAINED
  22. #endif
  23.  
  24. #ifdef ZA_BLOCKED
  25. static draw_request req;
  26. void UputZ4Planes(char far *image, unsigned x, unsigned y, int rows)
  27. {
  28.         req.dr_seg = _segment(image);
  29.         req.dr_imageo = _offset(image);
  30.         req.dr_offset = y*BPERROW + (x>>2);
  31.         req.dr_plane = x & 3;
  32.         req.dr_rows = rows;
  33.         UZ4PRequest(&req, 1);
  34. }
  35.  
  36. void UZ4PRequest(draw_request *dp, int nreq)
  37. {
  38.         _A_setMapMask();       /* Point gate to Map Mask Register */
  39.  
  40.         _ES = Scdraw_seg;
  41.     asm cld;
  42.         asm mov cx, nreq;
  43. ReqLoop:
  44.         asm push cx;
  45.     asm push ds;
  46.  
  47. #       if defined(__HUGE__)||defined(__LARGE__)||defined(__COMPACT__)
  48.                 /* Far data pointers */
  49.                 asm push es;
  50.                 asm les bx, dp;
  51.                 asm mov ax, es:[bx].dr_seg;
  52.                 asm mov ds, ax;
  53.                 asm mov si, es:[bx].dr_imageo;
  54.                 asm mov di, es:[bx].dr_offset;
  55.                 asm mov cx, es:[bx].dr_plane;
  56.                 asm mov bx, es:[bx].dr_rows;
  57.                 asm pop es;
  58. #       else
  59.                 /* Near data pointers */
  60.                 asm mov bx, dp;
  61.                 asm mov si, [bx].dr_imageo;
  62.                 asm mov di, [bx].dr_offset;
  63.                 asm mov cx, [bx].dr_plane;
  64.                 asm mov dx, [bx].dr_rows;               /* DX now destroyed ! */
  65.                 asm mov ax, [bx].dr_seg;
  66.                 asm mov ds, ax;
  67.                 asm mov bx, dx;
  68. #       endif
  69.  
  70. #else  ZA_BLOCKED
  71. void UputZ4Planes(char far *image, unsigned x, unsigned y, int rows)
  72. {
  73.         _A_setMapMask();       /* Point gate to Map Mask Register */
  74.  
  75.         _ES = Scdraw_seg;
  76.         _BX = rows;
  77.  
  78.     asm push ds;
  79.     asm lds si, image;
  80.     asm cld;
  81.         asm mov ax, y;          /* Get argument */
  82.         asm mov dx, BPERROW;
  83.         asm mul dx;
  84.  
  85.         asm mov cx, x;          /* Get argument */
  86.         asm mov di, cx;
  87.         asm shr di, 1;          /* Divide di by 4 */
  88.         asm shr di, 1;
  89.         asm and cx, 3;          /* cx now contains plane number */
  90.         asm add di, ax;
  91. #endif ZA_BLOCKED
  92.  
  93.         /*
  94.          * Common code for ZA_BLOCKED and !ZA_BLOCKED versions.
  95.          * -----------------------------------------------------
  96.          */
  97.  
  98.     asm mov ah, 0x10;
  99.         asm shl ah, cl;
  100. /*
  101.  *  For starting offset 0:  (leftmost)
  102.  *  #  cl  AH        AL      MapMask   di
  103.  *  1  4   001.0000  0001    1         +0
  104.  *  2  3   001.0000  0010    2         +0
  105.  *  3  2   001.0000  0100    4         +0
  106.  *  4  1   001.0000  1000    8         +0
  107.  *
  108.  *  For starting offset 1:
  109.  *  #  cl  AH        AL      MapMask   di
  110.  *  1  4   010.0000  0010    2         +0
  111.  *  2  3   010.0000  0100    4         +0
  112.  *  3  2   010.0000  1000    8         +0
  113.  *  4  1   010.0000 10000
  114.  *         000.0010  0001    1         +1
  115.  *
  116.  *  For starting offset 2:
  117.  *  #  cl  AH        AL      MapMask   di
  118.  *  1  4   100.0000  0100    4         +0
  119.  *  2  3   100.0000  1000    8         +0
  120.  *  3  2   100.0000 10000
  121.  *         000.0100  0001    1         +1
  122.  *  4  1   000.0100  0010    2         +0
  123.  *
  124.  *  For starting offset 3:  (rightmost)
  125.  *  #  cl  AH        AL      MapMask   di
  126.  *  1  4  1000.0000  1000    8         +0
  127.  *  2  3  1000.0000 10000
  128.  *         000.1000  0001    1         +1
  129.  *  3  2   000.1000  0010    2         +0
  130.  *  4  1   000.1000  0100    4         +0
  131.  */
  132.         asm push bp;
  133.         asm mov cx, BITPLANES;
  134. PlaneLoop:
  135.         /*
  136.      * Planes loop. CX contains plane counter.
  137.          * Scratch registers:
  138.      *      dx used to save bx, and to out instruction.
  139.          */
  140.         asm push cx;                    /* Save plane counter */
  141.  
  142.         /* Set the proper Map Mask */
  143.         asm mov al, ah;                 /* Shifting bit */
  144.     asm shr al, cl;                 /* Shift, according to (5 - plane #) */
  145.     asm test al, 0xF;               /* Not enough ? */
  146.         asm jnz  short Nowrap;
  147.                 asm inc di;             /* Wrap to next byte, i.e. next 4-group */
  148.                 asm shr ax, 1;          /* shr al,4;   shr ah,4 */
  149.                 asm shr ax, 1;
  150.                 asm shr ax, 1;
  151.         asm shr ax, 1;
  152. Nowrap:
  153.         asm mov dx, VGA_SER_GATE;
  154.         asm out dx, al;                 /* Select correct bitplane */
  155.  
  156.     asm push ax;                    /* Save shift bit in ah */
  157.         asm push di;                    /* Save starting offset */
  158.         asm mov  dx, bx;                /* Save row counter */
  159.  
  160.         asm mov  cx, bx;                /* Store row counter in cx */
  161.  
  162.                 /*++++same+++as++mputz4p.c+++*/
  163. RowLoop:
  164.                 /*
  165.                  * Scanlines loop. CX contains nrows.
  166.                  *
  167.                  * Sequence of the alhorithm follows the most frequent image
  168.                  * sequence: <skip>, <literal>, <skip/eol>.
  169.                  * Thus, at least 3 jumps per line are saved.
  170.                  *
  171.                  * Scratch registers:
  172.                  *      bx - saving the ram index (di)
  173.                  *      bp - saving the loop counter (cx)
  174.                  */
  175.                 asm mov bx, di;                 /* Save ram index */
  176.                 asm mov bp, cx;                 /* Save loop counter */
  177.                 asm xor ch, ch;                 /* Zero high byte, ch always zero */
  178.                 /* Loop until EOL */
  179. LineLoop:
  180.                         asm lodsb;              /* Get next image byte */
  181.                         asm or al, al;          /* Query flags */
  182.                         asm jg short Literal;   /* al > 0, so literally */
  183.                         asm je short String;    /* al == 0, so string */
  184.  
  185. Skip:                                           /* Otherwise skipping */
  186.                         asm neg al;             /* Invert counter */
  187.                         asm jo Eol;             /* Overflow, i.e. neg 128 */
  188.                         asm mov cl, al;         /* Move counter */
  189.                         asm add di, cx;         /* Advance the index */
  190.  
  191.                         asm lodsb;              /* Get next image byte */
  192.                         asm or al, al;          /* Query flags */
  193.                         asm je short String;    /* al == 0, so string */
  194. #if (BPERSCREEN/BITPLANES) > (SHAR_MAX-2)       /* <skip>, <skip> is available ? */
  195.                         asm jl short Skip;      /* al < 0, so skipping */
  196. #endif
  197.  
  198. Literal:                                        /* Otherwise literal */
  199.                         asm mov cl, al;         /* Move counter */
  200.                         asm rep movsb;          /* Copy cx bytes */
  201.                         asm lodsb;              /* Get next image byte */
  202.                         asm or al, al;          /* Query flags */
  203.                         asm jl short Skip;      /* al < 0, so skipping */
  204. #if (BPERSCREEN/BITPLANES) > (SHAR_MAX-2)       /* <literal>, <literal> is available ? */
  205.                         asm jg short Literal;   /* al > 0, so literally */
  206. #endif
  207.  
  208. String:                                         /* Otherwise string */
  209.                         asm lodsb;              /* Get counter byte */
  210.             asm mov cl, al;        /* Put counter to cl */
  211.                         asm lodsb;              /* Get color byte into al */
  212.                         asm rep stosb;          /* Store cx bytes of al */
  213.                         asm lodsb;              /* Get next image byte */
  214.                         asm or al, al;          /* Query flags */
  215.                         asm jg short Literal;   /* al > 0, so literally */
  216. #if (BPERSCREEN/BITPLANES) > (UHAR_MAX-1